const express = require('express');
const app = express();

const request = require('request');
const option = {
    method: 'get', //请求的方式
    encoding: null,
    url: 'https://trendings.herokuapp.com/repo?lang=javascript'//lang=javascript;since=daily,weekly,monthly等github框架排名接口
};
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});

app.get('/',function (error,ress) {
    request(option,function (err,res,body) {
        if (!err) {
            ress.json(JSON.parse(body))
        }
    });
});
app.listen('3000');